import os
import numpy as np
import pylab as py

subor = "/home/gandhi/Dropbox/Magnetometer/1/cat_pato_28-12-2008"


f = open(subor, 'r')
kk1 = 0.
kk2 = 0.
kk3 = 0.
kk4 = 0.
k = f.read()
mag = []
buf = np.zeros(45)
i = 1
while i < len(k):
    #print i
    #print ord(k[i])
    mag.append(ord(k[i]))
    i+=1
    
f.close()


for c in mag:
    #print c
    for ii in range(1, 31):
        buf[ii] = buf[ii+1]
    buf[31] = c
    if (buf[1]==255) and (buf[15+1]==255) and (buf[30+1]==255) and ((buf[14]==1) or (buf[14]==2)) and ((buf[15+14]==1) or (buf[15+14]==2)):
        k1 = buf[2] * 2**16 + buf[3] * 2**8 + buf[4]
        k2 = buf[5] * 2**16 + buf[6] * 2**8 + buf[7]
        k3 = buf[8] * 2**16 + buf[9] * 2**8 + buf[10]
        k4 = buf[11] * 2**16 + buf[12] * 2**8 + buf[13]
        synab = buf[14]
        citac = buf[15]
        
        if synab==1:
            kk1 = k1
            kk2 = k2
            kk3 = k3
            kk4 = k4
        else:
            k1 = k1-kk1
            k2 = k2-kk2
            k3 = k3-kk3
            k4 = k4-kk4
        
            
            print 'k1: '+str(k1)+' k2: '+str(k2)+' k3: '+str(k3)+' k4: '+str(k4)+' synab: '+str(synab)+' citac: '+str(citac)


print 'end'

#if (synab==1) {
#          k11 = k1;
#          k12 = k2;
#          k13 = k3;
#          k14 = k4;
#      }
#        else
#        {
#         //printf("\n");
#          kk1[ki] = k1-k11;
#          kk2[ki] = k2-k12;
#          kk3[ki] = k3-k13;
#          kk4[ki] = k4-k14;
#          //printf("k1=%06.0lf k2=%06.0lf k3=%06.0lf, k4=%06.0lf",k1,k2,k3,k4);
#          ki++;
